/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.encoder;


import java.io.Serializable;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;

/**
 * NOT YET IMPLEMENTED 
 * @author Joe Maisel
 */
public class PdfEncoder extends ResponseEncoder
{
	private Document document;

	/**
	 * @return the document
	 */
	public Document getDocument()
	{
		return document;
	}

	/**
	 * @param document
	 *            the document to set
	 */
	public void setDocument( Document document )
	{
		this.document = document;
	}

	@Override
	public void encode( Serializable model ) throws EncodingException
	{
		Document d = new Document( PageSize.A4 );
		try
		{
			PdfWriter.getInstance( d, getOutputStream() );
			d.open();

//			if( model instanceof List )
//			{
//
//				// List<User> users = (List<User>)model;
//				//				
//				// for( User u : users ){
//				// d.add ( new Paragraph(u.prettyPrint ()) );
//				// }
//			}

			d.close();
		}
		catch( DocumentException e )
		{
			e.printStackTrace();
			throw new EncodingException();
		}
	}

}
